/**
 * 
 * anthor liyingqi
 *  834777203@qq.com
 */
import { isMessageGo,vipPrivilegeGet } from '@/assets/public.js';

let routeList = {
  'zWebView/pages/highQualityShippers/index': '优质货主|显示工厂信息',
  'zWebView/pages/storeManage/storeManage': '仓库管理',
  'zWebView/pages/forwardingInformation/index': '货代名片',
  'zWebView/pages/vehicleSourceInformation/index': '车源信息',
  'zWebView/pages/publish/start': '运输发布',
  'zWebViewShop/pages/index/index': '中俄商城',
  'zWebViewShop/pages/caigou/index/index': '观看采购询单',
  'zWebViewShop/pages/caigou/publishInfo/index': '发布采购询单',
  'zWebViewShop/pages/tabbar/newUser/Mall/pointsMall': '积分商城',
  'zWebViewShop/pages/caigou/canyuOrder/index': '采购报价'
}


 const routeInterceptor = ()=> {
  let list = ["navigateTo","navigateBack","redirectTo"];
  list.forEach(item => {
      uni.addInterceptor(item, {
          invoke(e) { // 调用前拦截
            let keyUrl =  e.url ? e.url.split('?')[0] : '';
            console.log(keyUrl,'keyUrl')
            let route = keyUrl ? routeList[(e.webview || 'zWebViewShop') + keyUrl] : '';
            if (route) {
              let bole = vipPrivilegeGet(route);
              if (!bole) {
                return false;
              }
            }
            isMessageGo({
              action: item,
              data: e.url,
              title: e.title || "商城",
              webview: e.webview || 'zWebViewShop',
            })
            return false
          },
          fail(err) { // 失败回调拦截 
              console.log(err,'拦截失败');
          },
      })
  })
}


export default routeInterceptor;

